<?php
require_once $_SERVER['srcPath'].'\\MCrypt.php';

use GrouppaGroup\MCrypt;

class MCryptTest extends PHPUnit_Framework_TestCase
{
	
	/**
	 * @var MCrypt
	 */
	public $instance;
	protected function setUp()
	{
		$this->instance = new MCrypt();
	}
	private function encryptTest($text)
	{
		$encoded = $this->instance->encrypt($text);
		$decoded = $this->instance->decrypt($encoded);
		echo "\n\nTesting encryption for text: $text \nencrypted: $encoded\ndecrypted: $decoded";
		$this->assertEquals($text,$decoded);
		
	}
	private function encryptBytesTest($text)
	{

		$encoded = $this->instance->encryptToBytes($text);
		$this->assertTrue(strlen($encoded)%16 == 0);
		$decoded = $this->instance->decryptFromBytes($encoded);
		echo "\n\nTesting encryption to bytes for text: $text \nencrypted: $encoded\ndecrypted: $decoded";
		$this->assertEquals($text,$decoded);
	}
	public function dataForTest()
	{
		return array(
			array("bolek"),
			array(""),
			array("ala ma kota"),
			array('{"object1":"mono","object2":12,"object3":[12341,4231]}')
		);
	}
	/**
	 * @dataProvider dataForTest
	 */
	public function testEncrypt0($text)
	{
		$this->encryptTest($text);
	}
	/**
	 * @dataProvider dataForTest
	 */
	public function testEncryptBytes($text)
	{
		$this->encryptBytesTest($text);
	}
}